package com.xmutca.sso.provider.server;

import com.alibaba.dubbo.config.annotation.Service;
import com.xmutca.core.common.Result;
import com.xmutca.core.common.Results;
import com.xmutca.sso.api.Account;
import com.xmutca.sso.api.Menu;
import com.xmutca.sso.api.Permission;
import com.xmutca.sso.api.server.AccountService;
import com.xmutca.sso.dao.AccountDao;
import com.xmutca.sso.dao.MenuDao;
import com.xmutca.sso.dao.PermissionDao;
import com.xmutca.sso.dao.UserRoleDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-08 15:50
 */
@Service(version = "1.0.0", group = "sso", mock = "true")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;
    @Autowired
    private MenuDao menuDao;
    @Autowired
    private PermissionDao permissionDao;

    @Override
    public Result<Account> getByUsername(String username) {
        Account account = accountDao.getByUsername(username);
        return new Result<>(Result.Status.SUCCESS, account);
    }

    @Override
    public Result<Account> getById(String id) {
        Account account = accountDao.getById(id);
        return new Result<>(Result.Status.SUCCESS, account);
    }

    @Override
    public Results<Menu> queryMenu(String id) {
        List<Menu> menus = menuDao.queryMenus(id);
        return new Results<>(Results.Status.SUCCESS, menus);
    }

    @Override
    public Results<String> queryPermission(String id) {
        List<String> permissions = permissionDao.queryPermission(id);
        return new Results<>(Results.Status.SUCCESS, permissions);
    }
}
